<?php
/* SVN FILE: $Id: index.php 3 2009-12-25 03:21:28Z tahongawaka $ */
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
/**
* PHP version 5
*
* drupal2joomla is free software released under the MIT License.
*
* Project Name : drupal2joomla
*
* @author $Author: tahongawaka $
* @copyright $Copyright$
* @version $Revision: 3 $
* @lastrevision $Date: 2009-12-25 03:21:28 +0000 (Fri, 25 Dec 2009) $
* @modifiedby $LastChangedBy: tahongawaka $
* @lastmodified $LastChangedDate: 2009-12-25 03:21:28 +0000 (Fri, 25 Dec 2009) $
* @filesource $URL: http://drupal2joomla.googlecode.com/svn/trunk/index.php $
* @package drupal2joomla
*/

/* Configuration section.
 * Copy d2jconfig.dist.php to d2jconfig.php and insert the correct settings.
 */

require_once "d2jconfig.php";
require_once $drupalconfig;
require_once $joomlaconfig;

// Store drupal variables that we want to preserve in case the others get overwritten.
$drupaldbprefix = $db_prefix;
$drupaldb_url = $db_url;

// Joomla puts everything in a class.
$joomla = new JConfig();

/* Connect to database(s). If someone is familiar enough with PEAR MDB2,
   it can be incorporated, but I don't feel like learning it for this
   project. It would probably be easier, since the drupal connection
   string is already in url format. My databases are mysql, so the first
   person who isn't using mysql gets to add code here to incorporate
   your db format.
$db_url = 'mysql://dbuser:password@host/dbname';
*/
$tmp = explode("@", $drupaldb_url);
$tmpname = explode("/", $tmp[1]);
$drupalhost = $tmpname[0];
$drupaldb = $tmpname[1];
$tmpname = explode(":", $tmp[0]);
$drupaltype = $tmpname[0];
$drupaluser = substr($tmpname[1], 2);
$drupalpassword = $tmpname[2];

// Now we can connect to $drupaldb using $drupaluser $drupalpassword on $drupalhost
$drplink = mysql_connect($drupalhost, $drupaluser, $drupalpassword);
if (!$drplink) {
    die('Could not connect to drupal db: ' . mysql_error());
}
$db_selected = mysql_select_db($drupaldb, $drplink);
if (!$db_selected) {
    die ("Can't use $drupaldb : " . mysql_error());
}
/*
	var $dbtype = 'mysql';
	var $host = 'cannon.safesecureweb.com';
	var $user = 'ndchorus';
	var $db = 'ndchorus';
	var $password = 'et2brute';
*/

$jomlink = mysql_connect($joomla->host, $joomla->user, $joomla->password);
if (!$jomlink) {
    die('Could not connect to joomla db: ' . mysql_error());
}
$db_selected = mysql_select_db($joomla->db, $jomlink);
if (!$db_selected) {
    die ("Can't use $joomla->db : " . mysql_error());
}

// import content
/* We want the node title, body, creation timestamp, site creator, and
   path. First, just get all nodes and stick them in the sheet. Once
   we learn more about this, we can find only published nodes, or add
   nodes to front_page manager, or other specials.
*/

$query = "SELECT {$drupaldbprefix}node.vid, {$drupaldbprefix}node.title

from {$drupaldbprefix}node, {$drupaldbprefix}node_revisions

where {$drupaldbprefix}node.vid = {$drupaldbprefix}node_revisions.vid";

print $query;

/*$query = "select drupal_node_revisions.title, body, from_unixtime(timestamp) as date, type, name, dst from 
drupal_node_revisions, drupal_node,drupal_users, drupal_url_alias where
drupal_node_revisions.nid=drupal_node.nid and drupal_users.uid=drupal_node_revisions.uid and src like 
CONCAT("node/", drupal_node.nid) order by drupal_node_revisions.nid";
*/

// Import users. Apparently, passwords are stored differently.

